﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Collections;
using OgilvyOne.Borad.BLL;

public partial class preorder_GetDealeraspx : System.Web.UI.Page
{
    //protected string provinceStr = "";
    //protected string cityStr = "";
    //protected string dealerStr = "";
    protected string output = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        string op = Request.QueryString["op"];
        if (op == "GetProvince")
        {
            //省

            DataTable dt = new PreOrderBLL().GetProvince();
            foreach (DataRow row in dt.Rows)
            {
                output += "<option value=\"" + row["PROVINCE"] + "\">" + row["pcname"] + "</option>";
            }
            //foreach (object obj in hashProvince.Keys)
            //{
            //    string key = obj.ToString();
            //    output += "<option value=\"" + key + "\">" + dpt[obj] + "</option>";
            //}
        }
        //市
        string provinceId = Request.QueryString["pid"];
        if (!string.IsNullOrEmpty(provinceId))
        {
            Hashtable dpc = GetCityTable();
            foreach (object obj in dpc.Keys)
            {//key 省id obj2 市id ti[obj2] 名称
                string key = obj.ToString();
                if (provinceId == key)
                {
                    Hashtable ti = (Hashtable)dpc[obj];

                    int i = 0;
                    foreach (object obj2 in ti.Keys)
                    {
                        output += "<option value=\"" + obj2 + "\">" + ti[obj2] + "</option>";
                    }
                }
            }
        }
        //经销商
        string cityId = Request.QueryString["cid"];
        if (!string.IsNullOrEmpty(cityId))
        {
            Hashtable dpd = GetDealerTable();
            foreach (object obj in dpd.Keys)
            {//key 城市id  obj2 经销商id 经销商名称
                string key = obj.ToString();
                if (cityId == key)
                {
                    Hashtable ti = (Hashtable)dpd[obj];
                    int i = 0;
                    foreach (object obj2 in ti.Keys)
                    {
                        output += "<option value=\"" + obj2 + "\">" + ti[obj2] + "</option>";
                    }
                }
            }
        }
        Response.Write(output);
    }

    private Hashtable GetCityTable()
    {
        DataSet dealerds = new PreOrderBLL().GetAll();
        Hashtable dpc = new Hashtable();//市
        for (int i = 0; i < dealerds.Tables[0].Rows.Count; i++)
        {
            if (dpc.ContainsKey(dealerds.Tables[0].Rows[i]["PROVINCE"]))
            {
                Hashtable tc = ((Hashtable)dpc[dealerds.Tables[0].Rows[i]["PROVINCE"]]);
                tc[dealerds.Tables[0].Rows[i]["CITY"]] = dealerds.Tables[0].Rows[i]["ccname"];
            }
            else
            {
                Hashtable tt = new Hashtable();
                tt[dealerds.Tables[0].Rows[i]["CITY"]] = dealerds.Tables[0].Rows[i]["ccname"];
                dpc[dealerds.Tables[0].Rows[i]["PROVINCE"]] = tt;
            }
        }

        return dpc;
    }

    private Hashtable GetDealerTable()
    {
        DataSet dealerds = new PreOrderBLL().GetAll();
        Hashtable dpd = new Hashtable();//经销商
        for (int i = 0; i < dealerds.Tables[0].Rows.Count; i++)
        {
            if (dpd.ContainsKey(dealerds.Tables[0].Rows[i]["CITY"]))
            {
                Hashtable tc = ((Hashtable)dpd[dealerds.Tables[0].Rows[i]["CITY"]]);
                tc[dealerds.Tables[0].Rows[i]["ID"]] = dealerds.Tables[0].Rows[i]["DEALER_NAME"];
            }
            else
            {
                Hashtable tt = new Hashtable();
                tt[dealerds.Tables[0].Rows[i]["ID"]] = dealerds.Tables[0].Rows[i]["DEALER_NAME"];
                dpd[dealerds.Tables[0].Rows[i]["CITY"]] = tt;
            }
        }

        return dpd;
    }
}